package cn.diancan.listener;

import java.util.List;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import cn.diancan.model.SysAuthority;
import cn.diancan.service.SysAuthorityService;

public class ContextListener implements ServletContextListener{

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub
	
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		ApplicationContext ac=WebApplicationContextUtils.getWebApplicationContext(arg0.getServletContext());
		 SysAuthorityService authorityService=(SysAuthorityService) ac.getBean("sysAuthorityService");
		 List<SysAuthority> topList=authorityService.findTopList();
		 arg0.getServletContext().setAttribute("topList", topList);
		 List<String> allAuthorityUrls=authorityService.findAllUrl();//所有权限链接
		 arg0.getServletContext().setAttribute("allPrivilegeUrls", allAuthorityUrls);
		System.out.println("已准备好菜单数据");
	}

}
